<?php

namespace common\models\db;

use Yii;

/**
 * This is the model class for table "tbl_loan_record".
 *
 * @property int $id
 * @property int $user_id 用户ID
 * @property string $loan_type 贷款类型：商业贷款、公积金贷款、组合贷款
 * @property string $repayment_type 还款方式：等额本息、等额本金、对比两种方式
 * @property int $years 贷款年限
 * @property float $total_amount 贷款总额(万元)
 * @property string $created_at 创建时间
 *
 * @property CommercialLoanDetail $commercialLoanDetail
 * @property EqualResult $equalResult
 * @property FundLoanDetail $fundLoanDetail
 * @property LoanComparison[] $loanComparisons
 * @property LoanComparison[] $loanComparisons0
 * @property User $user
 * @property PrincipalResult $principalResult
 */
class LoanRecord extends \yii\db\ActiveRecord
{
    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return 'tbl_loan_record';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['user_id', 'loan_type', 'repayment_type', 'years', 'total_amount'], 'required'],
            [['user_id', 'years'], 'integer'],
            [['loan_type', 'repayment_type'], 'string'],
            [['total_amount'], 'number'],
            [['created_at'], 'safe'],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::class, 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'loan_type' => 'Loan Type',
            'repayment_type' => 'Repayment Type',
            'years' => 'Years',
            'total_amount' => 'Total Amount',
            'created_at' => 'Created At',
        ];
    }

    /**
     * Gets query for [[CommercialLoanDetail]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getCommercialLoanDetail()
    {
        return $this->hasOne(CommercialLoanDetail::class, ['record_id' => 'id']);
    }

    /**
     * Gets query for [[EqualResult]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getEqualResult()
    {
        return $this->hasOne(EqualResult::class, ['record_id' => 'id']);
    }

    /**
     * Gets query for [[FundLoanDetail]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getFundLoanDetail()
    {
        return $this->hasOne(FundLoanDetail::class, ['record_id' => 'id']);
    }

    /**
     * Gets query for [[LoanComparisons]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getLoanComparisons()
    {
        return $this->hasMany(LoanComparison::class, ['record1_id' => 'id']);
    }

    /**
     * Gets query for [[LoanComparisons0]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getLoanComparisons0()
    {
        return $this->hasMany(LoanComparison::class, ['record2_id' => 'id']);
    }

    /**
     * Gets query for [[User]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getUser()
    {
        return $this->hasOne(User::class, ['id' => 'user_id']);
    }

    /**
     * Gets query for [[PrincipalResult]].
     *
     * @return \yii\db\ActiveQuery
     */
    public function getPrincipalResult()
    {
        return $this->hasOne(PrincipalResult::class, ['record_id' => 'id']);
    }
}
